#include <new>

#include "Class/Component/Image.hpp"

namespace		Component
{
  sf::Image const		&Image::GetImage() const throw()
  {
	return (*this->_Image);
  }

  sf::Image		*Image::_GetImage()
  {
	if (!this->_Image)
	  this->_Image = new sf::Image;
	return (this->_Image);
  }

  bool			Image::SetImage(Image const &img)
  {
	if (this->_Image)
	  {
		delete this->_Image;
		this->_Image = NULL;
	  }
	if (!(this->_Image = new (std::nothrow) sf::Image(*img._Image)))
	  return (false);

	return (true);
  }
  bool			Image::SetImage(std::string const &path)
  {
	if (this->_Image)
	  {
		delete this->_Image;
		this->_Image = NULL;
	  }
	if (!(this->_Image = new (std::nothrow) sf::Image))
	  return (false);

	if (!this->_Image->LoadFromFile(path))
	  {
		delete this->_Image;
		this->_Image = NULL;
		return (false);
	  }
	return (true);
  }
  bool			Image::SetImage(sf::Image const &img)
  {
	if (this->_Image)
	  {
		delete this->_Image;
		this->_Image = NULL;
	  }
	if (!(this->_Image = new (std::nothrow) sf::Image(img)))
	  return (false);

	return (true);
  }

  void			Image::_Bind()
  {
	if (this->_Image && (this->_Image->GetWidth() > 1 || this->_Image->GetHeight() > 1))
	  this->_Image->Bind();
  }
}
